package com.cookie; /**
 * @author wzm
 * @create 2023-03-13 11:23
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/cookie03")
public class CookieServlet03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            Cookie cookie = new Cookie("name","ls");
            //默认浏览器关闭cookie删除
//        cookie.setMaxAge(604800);//7天
            cookie.setMaxAge(7*24*60*60);//程序自动计算
        //设置Cookie发送给服务器的地址信息
            cookie.setPath(request.getContextPath()+"/user");

            response.addCookie(cookie);

    }
}
